let jwt = require('../utils/jwt.js')
module.exports = (req, res, next) => {

  //处理公共的授权业务
  if (/login|logout|reg/.test(req.url)) {
    next()
  } else {
    //获取前端传递来的token
    let token = req.headers.token || req.body.token || req.query.token
    // 校验前端传递来的token
    jwt.verify(token).then(decode => {
      req.query.decode = decode //如果后续的接口需要数据的话，方便获取到  {username,_id} 
      next()
    }).catch(message => res.send({ err: 1, msg: "token验证失效或者未登录..." + message }))

  }
}